package com.hsoft.zhxy.common.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * Copyright ? 2020 哈尔滨工业大学软件工程股份有限公司. All rights reserved.
 *
 * @Title: WebMvcConfig.java
 * @Description:
 * @Prject: zhxy-if3.0
 * @author: liuyang
 * @date: 2020/10/27 16:19
 */
@Configuration
public class JsonHttpMessageConverterConfig implements WebMvcConfigurer {
    /**
     * 实现消息转换器配置方法，向当前的Http消息转换器列表增加FastJsonHttpMessageConverter
     *
     * @param converters 当前的Http消息转换器列表对象
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastJsonConverter.setFastJsonConfig(fastJsonConfig);
        converters.add(0, fastJsonConverter);//要显示指明将fastJsonConverter排在消息转换器管道列表的首位
    }
}
